/**
 * Created by admin on 2017/4/19.
 */
$(function () {

    function loginHander(data) {
        if(data.starts=="1"){
            alert(data.msg);
            window.location.href="information_success.html";
        }
    }

    $("#loginBtn").click(function () {
        var name = $("#userName").val();
        var phone = $("#userPhone").val();
        var name_return = util.isNull(name);
        var phone_return = util.phone(phone);
        if (name_return == 1) {
            if (phone_return == 1) {
                localStorage.setItem("userName", name);
                localStorage.setItem("userPhone", phone);
                $('.tishi').html("");
                window.location.href = "perfect_the_information.html";
            } else {
                $('.tishi').html("*请准确输入电话号码!");
                $("#userPhone").val("").focus();
            }
        } else {
            $('.tishi').html("*请输入用户姓名!");
            $("#userName").val("").focus();
        }
    });
    $("#submitBtn").click(function () {
        var ageType = "";
        var houseType = "";
        var carType = "";
        var codes="";
        $('input[name="age"]:checked').each(function () {
            ageType = $(this).val();
        });
        $('input[name="house"]:checked').each(function () {
            houseType = $(this).val();
        });
        $('input[name="car"]:checked').each(function () {
            carType = $(this).val();
        });
        var name = localStorage.getItem("userName");
        var phone = localStorage.getItem("userPhone");
        codes=util.GetQueryString("abc");
        if(codes==""){
            codes="123"
        }
        var data = {
            name: name,
            phone: phone,
            age: ageType,
            house: houseType,
            car: carType,
            code:codes
        };
        util.ajax("submitInformation", data, loginHander);
    });

});
